//
//  HomeController.swift
//  App
//
//  Created by chenyh on 2018/5/31.
//

import Vapor
import Leaf
import Stencil
import PathKit

final class HomeController {
    
    func index(_ req: Request) throws -> String {
        
        let context = [
            "articles": [
                Article(title: "Migrating from OCUnit to XCTest", author: "Kyle Fuller"),
                Article(title: "Memory Management with ARC", author: "Kyle Fuller"),
            ]
        ]

        
        let dir = try req.make(DirectoryConfig.self)
        let pathx = dir.workDir + "Resources/Views"
        let environment = Environment(loader: FileSystemLoader(paths: [Path(pathx)]))

        let render = try environment.loadTemplate(name: "test.html")
        let context111 = try render.render(context)
        print(context)
        return context111
        
//        let leaf = try req.make(LeafRenderer.self)
//        let context = ["title": "Welcome", "message": "Vapor and Leaf work hand in hand"]
//        return  leaf.render("home", context)
    }
    
    func index2(_ req: Request) throws -> Future<View> {
        let leaf = try req.make(LeafRenderer.self)
        let context = ["team": ["Malcolm", "Kaylee", "Jayne"]]
        return  leaf.render("home", context)
    }

}
